﻿
using UnityEngine;
using System;
using ScFramework.Core;

public static class FuncPhysicsAPI
{
    public static void AddForceAtLocalPosition(this SComponent func, Vector2 pos,float localAngle,float strength)
    {
        var force = MathTool.AngleToVector(localAngle);
        Debug.Log(force);
        force = func.gameObject.transform.TransformVector(force).normalized * strength;
        func.Rigid.AddForceAtPosition(force, func.transform.TransformPoint(pos));
    }
    public static void AddForceAtWordPosition(this SComponent func,Vector2 pos ,float worldAngle,float strength)
    {
        var force = MathTool.AngleToVector(worldAngle) * strength;
        func.Rigid.AddForceAtPosition(force, pos);
    }
    public static void RotateAroundLocalPoint(this SComponent comp,Vector2 pos,float angle)
    {
        if (comp.transform.localScale.x < 0)
        {
            angle *= -1;
        }
        comp.Rigid.transform.RotateAround(comp.transform.position, new Vector3(0, 0, 1), angle);
    }
    public static void SetVelocity(this SComponent comp,Vector2 v)
    {
        comp.Rigid.velocity = v;
    }
    public static void AddTorgueAtLocal(this SComponent func, Vector3 pos, Vector3 force)
    {
        throw new Exception();
    }
    public static void ChangeMotor(this SFuncBase func, JointMotor2D jointMotor,float motor,float maxMotor,WheelJoint2D joint)
    {
        jointMotor.maxMotorTorque = maxMotor;
        jointMotor.motorSpeed = motor;
        joint.motor = jointMotor;   
    }
    public static void SetObjectActive(this SFuncBase func,GameObject obj, bool active)
    {
        if (active)
        {
            
        }
    }
}